/**
 * <p>Title: LongteamSimulatePlan.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2013-8-29 上午02:18:56  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.common.zm.cInterface.cb;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * 接替计划模拟接口
 * <p>Title: LongteamSimulatePlan.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2013-8-29 上午02:18:56  张志芳  Create
 *</pre>
 */
public class LongteamSimulatePlan {
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 判断是否包含某年的模拟接替计划
	 * <p>Function: hasPlan</p>
	 * <p>Description: </p>
	 * <p>return value:String</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-8-29上午07:38:05 张志芳
	 * </p>
	 *
	 */
	public static String hasPlan(String year){
		Map map = new HashMap();
		map.put("fdYear", year);
		List<Map> list = dao.query("ZMCBSimulateFollowplan.queryHasPlan", map);//查询是否包含某年的模拟计划
		for(int i=0; i<list.size(); i++){
			String id = (String)list.get(i).get("fdKeyId");
			if(getPlanDetails(id)!=null){
				return id;
			}			
		}
		return null;
	}
	
	/**
	 * 根据主表ID获取明细数据
	 * <p>Function: getPlanDetails</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-8-29上午07:35:52 张志芳
	 * </p>
	 *
	 */
	public static List<Map> getPlanDetails(String id){
		Map map = new HashMap();
		map.put("fdForeignKey", id);
		List<Map> details = dao.query("ZMCBSimulateDetails.queryInterface", map);
		if(details.size()>0){
			return details;
		}
		return null;
	}
	
	/**
	 * 根据年份获所有的模拟接替计划主表数据
	 * <p>Function: getPlans</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-8-22上午08:17:20 张志芳
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<Map> getPlans(String year){
		Map map = new HashMap();
		map.put("fdYear", year);
		return dao.query("ZMCBSimulateFollowplan.queryHasPlan", map);//查询是否包含某年的模拟计划
	}
	
	/**
	 * 根据年份获所有的模拟接替计划主表数据Block
	 * <p>Function: getPlansBlock</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-9-2上午02:45:06 张志芳
	 * </p>
	 *
	 */
	public static EiBlock getPlansBlock(String blockName, String year){
		EiBlock block = new EiBlock(blockName);

		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("fdPlanName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdBeginYear");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdEndYear");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		block.setRows(getPlans(year));
		return block;
	}
}
